/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import CRUD.ThreadHome;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.actions.DispatchAction;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import ModeratorOperations.ModeratorManageThreads;
import xmlMapping.Thread;
/**
 *
 * @author Mostafa
 */
public class StickThreadAction extends DispatchAction {

   
    public ActionForward stick(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
     Integer id= Integer.parseInt(request.getParameter("threadid"));
     ThreadHome th=new ThreadHome();
     Thread stickthread= th.findById(id);
     String fname=stickthread.getForum().getName();
     Integer fid=stickthread.getForum().getForumId();
     stickthread.setSticky(true);
     th.session.close();
     ModeratorManageThreads management=new ModeratorManageThreads();
     
     management.stick(stickthread);
        
         response.sendRedirect("ViewForum.jsp?forumid="+fid+"&forumname="+fname);
         return null;
    }

    /**
     * This is the Struts action method called on
     * http://.../actionPath?method=myAction2,
     * where "method" is the value specified in <action> element : 
     * ( <action parameter="method" .../> )
     */
    public ActionForward unstick(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
     Integer id= Integer.parseInt(request.getParameter("threadid"));
     ThreadHome th=new ThreadHome();
     Thread stickthread=th.findById(id);
     String fname=stickthread.getForum().getName();
     Integer fid=stickthread.getForum().getForumId();
     stickthread.setSticky(false);
     th.session.close();
     ModeratorManageThreads management=new ModeratorManageThreads();
     management.stick(stickthread);
        
         response.sendRedirect("ViewForum.jsp?forumid="+fid+"&forumname="+fname);
         return null;
        
    }
}
